package com.manshutingyu.common.mq.producer;
@Componet
public class RocketMQProducer {
    @Autowired
private RocketMQTemplate rocketMQTemplate;
    // 同步发送消息
   /* public void sendSyncMessage(String topic, String tag, String message) {
        rocketMQTemplate.syncSend(topic, tag, message);
    }*/

    // 同步发送消息
    public SendResult sendSyncMessage(String topic, String message) {
      //  return rocketMQTemplate.syncSend(topic, MessageBuilder.withPayload(message).build());
        return rocketMQTemplate.syncSend(topic,message).build();
    }

    // 异步发送消息（带回调）
    public void sendAsyncMessage(String topic, String message) {
        rocketMQTemplate.asyncSend(topic, message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                log.info("异步消息发送成功: {}", sendResult);
            }
            @Override
            public void onException(Throwable e) {
                log.error("异步消息发送失败", e);
            }
        });
    }

    // 发送延迟消息（delayLevel: 1=1秒, 2=5秒...）
    public void sendDelayedMessage(String topic, String message, int delayLevel) {
       // rocketMQTemplate.syncSend(topic, MessageBuilder.withPayload(message).build(), 3000, delayLevel);
        rocketMQTemplate.syncSend(topic,message, 3000, delayLevel);
    }
}
